package trainfengxing.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import trainfengxing.pojo.Result;
import trainfengxing.pojo.user;

import java.util.List;

@Slf4j
@RestController
public class userController {

    @Autowired
    private trainfengxing.service.userService userService;

    @GetMapping("/selectuser")
    public Result selectuser(){
        log.info("查询用户信息");
        List<user> users = userService.selectuser();
        return Result.success(users);
    }

    @PostMapping("/updateuser")
    public Result updateuser(@RequestBody user user){
        log.info("修改用户信息");
        userService.updateuser(user);
        return Result.success();
    }

    @PostMapping("/register")
    public Result register(@RequestBody user user){
        log.info("用户注册: {}", user);
        // 设置默认角色为普通用户
        user.setUserRole("购票者");
        userService.insertUser(user);
        return Result.success();
    }

}
